import { request } from '@/utils/request'
import type { Product, ProductSearch } from '@/types/product'
import type { PageQuery } from '@/types/api'

// 获取产品列表
export function getProductList(params?: ProductSearch) {
  return request<Product[]>({
    url: '/product/list',
    method: 'get',
    params
  })
}

// 分页获取产品列表
export function getProductPage(params: PageQuery & ProductSearch) {
  return request<{
    rows: Product[]
    total: number
    pages?: number
    current?: number
    size?: number
  }>({
    url: '/product/page',
    method: 'get',
    params
  })
}

// 获取产品详情
export function getProductDetail(productId: number) {
  return request<Product>({
    url: `/product/${productId}`,
    method: 'get'
  })
}

// 新增产品
export function addProduct(data: Partial<Product>) {
  return request({
    url: '/product',
    method: 'post',
    data
  })
}

// 修改产品
export function updateProduct(data: Partial<Product>) {
  return request({
    url: '/product',
    method: 'put',
    data
  })
}

// 删除产品
export function deleteProduct(productId: number) {
  return request({
    url: `/product/${productId}`,
    method: 'delete'
  })
}